package com.lgqz.himalayafm.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lgqz.himalayafm.R;

import java.util.List;

/**
 * 主播那一页的第一个很多电视台的Adapter
 * Created by Administrator on 2016/12/4/004.
 */

public class RadioAdapter extends RecyclerView.Adapter<RadioAdapter.ViewHodler> {
    private List<String> list;
    private List<String> list1;
    private Context context;
    private ViewHodler viewHodler;
    private RadioAdapter adapter;
    private MyItemClickListener listener;

    public void setOnItemClickListener(MyItemClickListener listener) {
        this.listener = listener;
    }

    public RadioAdapter(List<String> list, Context context, List<String> list1) {
        this.list = list;
        this.list1 = list1;
        this.context = context;
        adapter = this;

    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(viewType, parent, false);
        viewHodler = new ViewHodler(view);
        return viewHodler;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == list1.size()) {
            return R.layout.fragment_radios_item_image;
        }
        return R.layout.fragment_radios_item;
    }

    @Override
    public void onBindViewHolder(final ViewHodler holder, int position) {

        if (listener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int position = holder.getLayoutPosition();
                    listener.onItemClickListener(holder.itemView, position);
                }
            });

        } if (position==list1.size()) {
        } else{



                holder.tv.setText(list1.get(position));

            }

    }

    @Override
    public int getItemCount() {
        return list1.size()+1;
    }

    public class ViewHodler extends RecyclerView.ViewHolder {

        private final TextView tv;
        private final ImageView imageView;

        public ViewHodler(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.id_num);
            imageView = (ImageView) itemView.findViewById(R.id.id_image);
        }
    }

    /**
     * 监听器的回掉接口
     */
    public interface MyItemClickListener {
        void onItemClickListener(View view, int position);

    }

}
